package xquery;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.base.Resource;
import org.xmldb.api.base.ResourceIterator;
import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.modules.XPathQueryService;
public class XQuery 
{
    public static void main(String[] args)throws Exception
    {                    
        String driver = "org.exist.xmldb.DatabaseImpl"; 
        Class cl = Class.forName(driver);
        Database database = (Database) cl.newInstance();
        database.setProperty("create-database", "true");
        DatabaseManager.registerDatabase(database); 
        Collection col = DatabaseManager.getCollection("xmldb:exist://localhost:8899/exist/xmlrpc/BD/", "admin", "123");
        XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
        service.setProperty("pretty", "true");
        service.setProperty("encoding", "UTF-8");
        String Usuario="FMSORI";
        String Clave="123";
        ResourceSet result = service.query("for $b in doc('Schema.xml')//HVDocentes/Usuario where $b/Usuario = '"+Usuario+"'return $b/nombre/apellido");
        ResourceIterator i = result.getIterator();
        System.out.println("..::"+result.getSize()+"::.."+i);
        while (i.hasMoreResources()) 
        {
            Resource r = i.nextResource();
            System.out.println("hola: "+(String) r.getContent());
        }
    }
}
